package logic

import (
	"api/model/mysql"
	"context"
	"house_srv/house"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddImgLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddImgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddImgLogic {
	return &AddImgLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddImgLogic) AddImg(in *house.AddImgRequest) (*house.AddImgResponse, error) {
	// todo: add your logic here and delete this line

	var h mysql.House
	mysql.DB.Where("house_id=?", in.HouseId).Find(&h)

	img := mysql.Image{
		HouseId: int(in.HouseId),
		Url:     in.Url,
		Name:    in.Name,
	}

	mysql.DB.Create(&img)

	return &house.AddImgResponse{
		Id: int64(img.ID),
	}, nil
}
